<template>
  <el-header height="70px" class="head-box main-v-center">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item v-for="item of breadcrumb">{{item.title}}</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="main-right">
      <el-container class="main-v-center">
        <el-dropdown style="font-size:16px;" @command="handleCommand">
          <span class="el-dropdown-link">
            {{username}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="logout">
              <i class="fa fa-power-off icon main-text-color"></i> 退出登录
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <img class="head-logo-img" :src="userhead" alt />
      </el-container>
    </div>
  </el-header>
</template>
<script>
import { mapGetters } from "vuex";

export default {
  name: "igfheader",
  props: {},
  data() {
    return {};
  },
  methods: {
    handleCommand(command) {
      if (command == "logout") {
        this.$store.dispatch("user_logout");
        this.$router.push({ name: "login", query: {} });
      }
    }
  },
  computed: {
    ...mapGetters(["breadcrumb", "user"]),
    username() {
      let title = "";
      if (this.user == null) return "";
      if (this.user.role == 0) title = "管理员：";
      return title + this.user.username;
    },
    userhead() {
      if (this.user == null) return "";
      return require("../assets/" + this.user.role + ".png");
    }
  }
};
</script>
<style>
.head-box {
  background-color: #ededed;
  border-bottom: 1px solid #d9dee4;
}

.head-logo-img {
  width: 30px;
  height: 30px;
  border-radius: 5px;
  margin-left: 10px;
}
</style>

